package com.nuanshui.heatedloan.socket.msg.handler;

import io.netty.channel.ChannelHandlerContext;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.nuanshui.heatedloan.annotation.MsgHandler;
import com.nuanshui.heatedloan.socket.ProtoMsg.Msg;
import com.nuanshui.heatedloan.socket.client.Client;
import com.nuanshui.heatedloan.socket.client.ClientManager;
import com.nuanshui.heatedloan.socket.msg.MsgIdType;
import com.nuanshui.heatedloan.socket.server.TCPServer;

/**
 * 心跳消息处理
 * @author GH
 *
 */
@MsgHandler(MsgIdType.CLIENT_HEART_BEAT_MSG)
public class ClientHeartbeatMsgHandler implements IHandler {

	private Logger logger = LoggerFactory.getLogger(ClientHeartbeatMsgHandler.class);
	@Override
	public void doHandle(Msg m, ChannelHandlerContext ctx) {		
		logger.info(m.getMsgId()+"   "+m.getSafeToken()+"   ");
		try {
				logger.info("心跳消息:"+m.getSafeToken()+"  "+m.getUserId());
				Client client = ClientManager.getClient(ctx);
				if(client!=null) {
					ClientManager.setClientLastTime(ctx, client);
				}else {
					logger.info("客户端不存在");
				}
				
		} catch (Exception e) {
			logger.error("登录消息处理失败",e);
		}
		TCPServer.getSingletonInstance().send(m.toBuilder());	
	}
	
	public ClientHeartbeatMsgHandler() {
		
	}

}
